//package com.uphone.kingmall;
//
//import android.app.Notification;
//import android.app.NotificationChannel;
//import android.app.NotificationManager;
//import android.app.PendingIntent;
//import android.content.BroadcastReceiver;
//import android.content.Context;
//import android.content.Intent;
//import android.graphics.Color;
//import android.os.Build;
//import android.os.Bundle;
//import android.text.TextUtils;
//
//import com.blankj.utilcode.util.LogUtils;
//import com.blankj.utilcode.util.ToastUtils;
//import com.uphone.kingmall.activity.MessageActivity;
//import com.uphone.kingmall.activity.order.AllOrderActivity;
//import com.uphone.kingmall.activity.order.OrderDetailActivity;
//import com.uphone.kingmall.activity.order.OrderRefundListActivity;
//import com.uphone.kingmall.activity.personal.LiuYanReplyActivity;
//import com.uphone.kingmall.base.BaseActivity;
//import com.uphone.kingmall.main.MainActivity;
//import com.uphone.kingmall.utils.ActivityCollector;
//
//import java.util.List;
//
//import cn.jpush.android.api.JPushInterface;
//
///**
// * @ Create_time: 2018/5/10 on 14:48.
// * @ description：
// * @ author: xman  15703379121@163.com
// */
//public class JPushReceiver extends BroadcastReceiver {
//    private NotificationManager nm;
//    private Context context;
//
//    @Override
//    public void onReceive(Context context, Intent intent) {
//        this.context = context;
//        if (null == nm) {
//            nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//        }
//
//        Bundle bundle = intent.getExtras();
//        if (null == bundle)
//            return;
//
//        try {
//            int notificationId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);//通知id
//            if (notificationId == 0) {
//                return;
//            }
//            String notificationTitle = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);//通知栏标题信息
//            String notificationInfo = bundle.getString(JPushInterface.EXTRA_ALERT);//通知栏详情信息
//            String notificationExtras = bundle.getString(JPushInterface.EXTRA_EXTRA);//通知携带内容
//            LogUtils.e("id:" + notificationId + "\ntitle:" + notificationTitle + "\ninfo:" + notificationInfo + "\nextras:" + notificationExtras);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
//            LogUtils.e("JPush用户注册成功");
//        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
//            LogUtils.e("接收到推送下来的自定义消息:" + bundle.getString(JPushInterface.EXTRA_MSG_ID + bundle.getString(JPushInterface.EXTRA_MESSAGE)));
//        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
//            LogUtils.e("接收到推送下来的通知");
//            receivedMessage(bundle);
//        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
//            LogUtils.e("打开推送");
//            openNotification(bundle);
//        } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent
//                .getAction())) {
//            LogUtils.e("用户收到到RICH PUSH CALLBACK: "
//                    + bundle.getString(JPushInterface.EXTRA_EXTRA));
//        } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
//            boolean connected = intent.getBooleanExtra(
//                    JPushInterface.EXTRA_CONNECTION_CHANGE, false);
//            LogUtils.e("[MyReceiver]" + intent.getAction()
//                    + " connected state change to " + connected);
//        } else {
//            LogUtils.e("Unhandled intent - " + intent.getAction());
//        }
//    }
//
//    /**
//     * 接收到消息时
//     *
//     * @param bundle
//     */
//    private void receivedMessage(Bundle bundle) {
//        String notificationInfo = bundle.getString(JPushInterface.EXTRA_ALERT);//通知栏详情信息
//        if (!TextUtils.isEmpty(notificationInfo)) {
//            ToastUtils.showShort(notificationInfo);
//        }
//        List<BaseActivity> activities = ActivityCollector.activities;
//        LogUtils.e("activitys:"+activities);
//        if (activities != null && activities.size() > 0) {
//            for (int i = activities.size() - 1; i >= 0; i--) {
//                BaseActivity baseActivity = activities.get(i);
//                if (baseActivity != null) {
//                    baseActivity.loadJPush();
//                    LogUtils.e("loadJpush:");
//                    if (baseActivity instanceof MainActivity){
//                        ((MainActivity)baseActivity).loadJPush();
//                    }else if (baseActivity instanceof AllOrderActivity){
//                        ((AllOrderActivity)baseActivity).loadJPush();
//                    }else if (baseActivity instanceof OrderRefundListActivity){
//                        ((OrderRefundListActivity)baseActivity).loadJPush();
//                    }else if (baseActivity instanceof OrderDetailActivity){
//                        ((OrderDetailActivity)baseActivity).loadJPush();
//                    }else if (baseActivity instanceof LiuYanReplyActivity){
//                        ((LiuYanReplyActivity)baseActivity).loadJPush();
//                    }
//                }
//            }
//        }
//    }
//
//    /**
//     * 点击通知时
//     *
//     * @param bundle
//     */
//    private void openNotification(Bundle bundle) {
//        LogUtils.e("openNotification:");
//        try {
//            Intent intent = new Intent(context, MessageActivity.class);
//            intent.putExtra("position", 1);//通知消息
//            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
//                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
//            context.startActivity(intent);
//        } catch (Exception e) {
//            LogUtils.e("通知异常：" + e.getMessage());
//            e.printStackTrace();
//        }
//    }
//
//}
